package cn.bytecollege.admin.controller;

import cn.bytecollege.admin.service.OrderService;
import cn.bytecollege.common.constant.Resource;
import cn.bytecollege.common.entity.Orders;
import cn.bytecollege.common.entity.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author NJK
 */
@WebServlet(name = "OrderListController",value = "/admin/orderList")
public class OrderListController extends HttpServlet {
    private OrderService orderService = null;
    public OrderListController(){
        orderService = new OrderService();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取数据
        String index = request.getParameter("index");
        String size = request.getParameter("size");
        String pay = request.getParameter("payFlag");
        //将数据转型
        Integer pageIndex = (index==null)?1:Integer.valueOf(index);
        Integer pageSize = (size==null)?10:Integer.valueOf(size);
        Integer payFlag = Integer.valueOf(pay);
        //执行分页查询语句
        Page<Orders> page = orderService.findOrderByPage(pageIndex,pageSize,payFlag);
        //封装
        request.setAttribute("page",page);
        //跳转页面
        if(payFlag == 0){
            //支付标志位等于0，跳转到未支付订单
            request.getRequestDispatcher(Resource.PAGE_LOCATION+"/admin/unPayList.jsp").forward(request,response);
        }else {
            //支付标志位不等于0（也就是等于1），跳转到已支付订单
            request.getRequestDispatcher(Resource.PAGE_LOCATION+"/admin/payList.jsp").forward(request,response);
        }
    }
}
